Class Car

java.lang.Object
  extended by Car

public class Car
extends java.lang.Object

Seat models a seat in a car in a passenger train.

Version:
2.0 May 12th, 2016
Author:
Aly Moursy, 100910299

Field Summary
static double BUSINESS_SEAT_COST
          The cost of a business class seat, in dollars.
static int BUSINESS_SEATS
          The number of seats in a business class car.
static double ECONOMY_SEAT_COST
          The cost of an economy class seat, in dollars.
static int ECONOMY_SEATS
          The number of seats in an economy class car.
 
Constructor Summary
Car(int carId, boolean isBusinessClass)
          Constructs a new Car object with the specified id.
 
Method Summary
 boolean bookNextSeat()
          Attempts to book a seat.
 boolean cancelSeat(int seatNo)
          Cancels the booking for the specified seat, which must be between 1 and the maximum number of seats in the car.
 int id()
           
 boolean isBusinessClass()
          Returns true if this is a business-class car, false if this is an economy-class car.
 Seat[] seats()
          Returns this car's list of seats.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUSINESS_SEAT_COST

public static final double BUSINESS_SEAT_COST
The cost of a business class seat, in dollars.

See Also:
Constant Field Values

BUSINESS_SEATS

public static final int BUSINESS_SEATS
The number of seats in a business class car.

See Also:
Constant Field Values

ECONOMY_SEAT_COST

public static final double ECONOMY_SEAT_COST
The cost of an economy class seat, in dollars.

See Also:
Constant Field Values

ECONOMY_SEATS

public static final int ECONOMY_SEATS
The number of seats in an economy class car.

See Also:
Constant Field Values
Constructor Detail

Car

public Car(int carId,
           boolean isBusinessClass)
Constructs a new Car object with the specified id. If parameter isBusinessClass is true, the car is a business-class car. If parameter isBusinessClass is false, the car is an economy-class car.

Parameters:
carId: - cars identifier
isBusinessClass: - is the seat business class or economy class
Method Detail

bookNextSeat

public boolean bookNextSeat()
Attempts to book a seat. If successful, this method prints a ticket and returns true. If no seats are available, this method returns false.

Returns:
returns true if it was able to book the seat

cancelSeat

public boolean cancelSeat(int seatNo)
Cancels the booking for the specified seat, which must be between 1 and the maximum number of seats in the car. If the seat number is valid and if the seat has been reserved, this method cancels the booking for that seat and returns true. If the seat number is not valid, this method returns false. If the seat number is valid, but the seat has not been reserved, this method returns false.

Parameters:
seatNo: - number of the seat
Returns:
True if seat # is valid

id

public int id()
Returns:
the id of this car.

isBusinessClass

public boolean isBusinessClass()
Returns true if this is a business-class car, false if this is an economy-class car.

Returns:
Returns true if it is a business class seat, return false if economy

seats

public Seat[] seats()
Returns this car's list of seats. This method is intended for testing purposes only, and should not be called by other objects, as it may be removed from the final version of this class.

Returns:
The seats in this car, an array of Seat objects.